package org.example.thread.thread01;

/**
 * @Auther:Liu
 * @Testname:Demo04
 * @Date:2025/8/14 10:49
 */
public class Demo04 {

    private int num=0;

//    public synchronized void changeNUm(){
//        String name = Thread.currentThread().getName();
//        System.out.println(name + "准备执行对count自增的操作,当前count:" + num);
//        num+=1;
//        System.out.println(name + "执行后,当前count:" + num);
//    }

    public  void changeNUm(){
        String name = Thread.currentThread().getName();
        synchronized(this) {
            System.out.println(name + "准备执行对count自增的操作,当前count:" + num);
            num += 1;
            System.out.println(name + "执行后,当前count:" + num);
        }
    }
}
